<?php
// +----------------------------------------------------------------------
// | 权限节点模块
// +----------------------------------------------------------------------
// | Author: 李乾坤 <261001642@qq.com>
// +----------------------------------------------------------------------
class AuthRuleAction extends CommonAction {
	public function _filter($map)
	{
        if (!empty($_REQUEST['name'])){
            $map['name']=array('like','%'.$_REQUEST['name'].'%');
        }
        if (!empty($_REQUEST['title'])){
            $map['title']=array('like','%'.$_REQUEST['title'].'%');
        }
        if (!empty($_REQUEST['remark'])){
            $map['remark']=array('like','%'.$_REQUEST['remark'].'%');
        }
        if(!empty($_GET['group_id'])) {
            $map['group_id'] =  $_GET['group_id'];
            $this->assign('nodeName','分组');
        }elseif(empty($_POST['search']) && !isset($map['pid']) ) {
			$map['pid']	=	0;
		}
		$_SESSION['currentNodeId']	=	$map['pid'];
		//获取上级节点
		$AuthRule  = D("AuthRule");
        if(isset($map['pid'])) {
            if($AuthRule->getById($map['pid'])) {
                $this->assign('level',$AuthRule->level+1);
                $this->assign('nodeName',$AuthRule->title);
            }else {
                $this->assign('level',1);
            }
        }
        return $map;
	}
	public function _before_index() {
		$model	=	M("Group");
		$list	=	$model->Where('status=1')->getField('id,title');
		$this->assign('groupList',$list);
	}
	public function _before_add() {
		$this->_before_index();
		$AuthRule	=	D("AuthRule");
		$AuthRule->getById($_SESSION['currentNodeId']);
        $this->assign('pid',$AuthRule->id);
		$this->assign('level',$AuthRule->level+1);
	}

	public function _before_edit() {
		$this->_before_index();
	}
	/**
     +----------------------------------------------------------
     * 默认排序操作
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @return void
     +----------------------------------------------------------
     * @throws FcsException
     +----------------------------------------------------------
     */
    public function sort()
    {
		$AuthRule = D('AuthRule');
        if(!empty($_GET['sortId'])) {
            $map = array();
            $map['status'] = 1;
            $map['id']   = array('in',$_GET['sortId']);
            $sortList   =   $AuthRule->where($map)->order('sort asc')->select();
        }else{
            if(!empty($_GET['pid'])) {
                $pid  = $_GET['pid'];
            }else {
                $pid  = $_SESSION['currentNodeId'];
            }
            if($AuthRule->getById($pid)) {
                $level   =  $AuthRule->level+1;
            }else {
                $level   =  1;
            }
            $this->assign('level',$level);
            $sortList   =   $AuthRule->select(array(
                'where'=>'status=1 and pid='.$pid.' and level='.$level,
                'order'=>'sort asc')
                );
        }
        $this->assign("sortList",$sortList);
        $this->display('Public:sort');
        return;
    }
    function cache(){
        R('Index/getMenu',array(null,true));
        //$this->getMenu(null,true);
        $this->success('缓存生成成功!');
    }
}
?>